﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Osg;
using ZFGK.Addins;
using ZFGK.DocFrame.Primaries;
using ZFGK.DocFrame.Utility;
using ZFGK.OCC.Utility;
using ZFGK.OSG.Doc.CustomEntity;
using ZFGK.OSG.DocUI;
using ZFGK.OSG.DocUI.CmdEnables;
using ZFGK.OSG.DocUI.Utility;
using ZFGK.OSG.UI;
using ZFGK.OSG.UI.Actions;
using ZFGK.OSG.Utility;
using ZFGK.OsgOcc.Doc.CustomEntity;
using ZFGK.Utility;

namespace OSS.Doc.Cmds
{
    [OnlyDocCmdEnable]
    public class CutCmd : IExtendCommand
    {
        /// <summary>
        /// Executes the specified command data.
        /// </summary>
        /// <param name="cmdData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <returns>CmdResult.</returns>
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var docViewForm = cmdData.ViewForm as OsgDocViewForm;
            if (docViewForm == null) return CmdResult.Cancel;

            var osgViewCtrl = docViewForm.View as ZfOsgViewCtrl;
            var actionUtility = osgViewCtrl.ActionUtility;
            var activeDocument = docViewForm.OsgDocViewCtrl.ActiveDocument;

            // 选择一个实体
            ZfOsgOccEntity ent1, ent2;
            if (!actionUtility.PickModel("选择第一个实体:", activeDocument, out ent1)
                || !actionUtility.PickModel("选择第二个实体:", activeDocument, out ent2))
            {
                return CmdResult.Cancel;
            }

            activeDocument.InStoreUndoGroup(delegate()
            {
                ent1.Shape = ent1.Shape.Cut(ent2.Shape);

                ent2.Deleted = true;
            });
            ent1.Update();
            ent2.Update();

            return CmdResult.Succeed;
        }
    }
}
